package de.duester.vectordrawing.object;

import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Canvas;
import android.graphics.PointF;
import android.graphics.RectF;
import de.duester.vectordrawing.GraphicalObject;

/**
 * @author Maxim Duester
 */
public class Arc extends GraphicalObject {
	private float width;
	private float height;
	private int startAngle;
	private int endAngle;

	/**
	 * 
	 */
	public Arc() {
	}

	/**
	 * @param p
	 * @param width
	 * @param height
	 * @param startAngle
	 * @param endAngle
	 */
	public Arc(PointF p, float width, float height, int startAngle, int endAngle) {
		super(p);
		this.width = width;
		this.height = height;
		this.startAngle = startAngle;
		this.endAngle = endAngle;
	}

	/**
	 * @return
	 */
	public float getWidth() {
		return width;
	}

	/**
	 * @return
	 */
	public float getHeight() {
		return height;
	}

	/* (non-Javadoc)
	 * @see de.duester.vectordrawing.GraphicalObject#getNonRotatedImage()
	 */
	@Override
	protected Bitmap getNonRotatedImage() {
		paint.setColor(getColor(0));

		PointF p = getScaledAndTransformedRelative(new PointF(width, height));
		float w = p.x;
		float h = p.y;
		RectF r = new RectF(0, 0, w, h);

		Bitmap b = Bitmap.createBitmap((int) w, (int) h, Config.ARGB_8888);
		Canvas canvas = new Canvas(b);
		canvas.drawArc(r, startAngle, endAngle, false, paint);
		return b;
	}

	/* (non-Javadoc)
	 * @see de.duester.vectordrawing.GraphicalObject#copy()
	 */
	@Override
	public GraphicalObject copy() {
		Arc a = (Arc) super.copy();
		a.width = width;
		a.height = height;
		a.startAngle = startAngle;
		a.endAngle = endAngle;
		return a;
	}

	/* (non-Javadoc)
	 * @see de.duester.vectordrawing.GraphicalObject#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object o) {
		if (!super.equals(o))
			return false;
		Arc a = (Arc) o;
		return (width == a.width && height == a.height && startAngle == a.startAngle && endAngle == a.endAngle);
	}
}
